<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>AI面试系统 - 结果</title>
    <link
      href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/css/bootstrap.min.css"
      rel="stylesheet"
    />
    <link
      rel="stylesheet"
      href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.10.0/font/bootstrap-icons.css"
    />
  </head>
  <body>
    <nav
      class="navbar navbar-expand-lg navbar-dark"
      style="
        background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
        box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
      "
    >
      <div class="container">
        <a class="navbar-brand d-flex align-items-center" href="#">
          <i class="bi bi-robot me-2" style="font-size: 1.5rem"></i>
          AI面试系统
        </a>
        <button
          class="navbar-toggler border-0"
          type="button"
          data-bs-toggle="collapse"
          data-bs-target="#navbarNav"
        >
          <span class="navbar-toggler-icon"></span>
        </button>
        <div class="collapse navbar-collapse" id="navbarNav">
          <ul class="navbar-nav ms-auto">
            <li class="nav-item">
              <span class="nav-link d-flex align-items-center">
                <i class="bi bi-person-circle me-2"></i>
                欢迎，[[${#authentication?.principal?.username ?: '游客'}]]
              </span>
            </li>
            <li class="nav-item">
              <a
                class="nav-link d-flex align-items-center"
                th:href="@{/interviews}"
              >
                <i class="bi bi-list-ul me-2"></i>我的面试
              </a>
            </li>
            <li class="nav-item">
              <a
                class="nav-link d-flex align-items-center"
                th:href="@{/logout}"
              >
                <i class="bi bi-box-arrow-right me-2"></i>退出登录
              </a>
            </li>
          </ul>
        </div>
      </div>
    </nav>

    <div class="container mt-4">
      <div class="row">
        <div class="col-lg-10 offset-lg-1">
          <div
            class="card shadow-lg border-0 mb-4"
            style="border-radius: 20px; overflow: hidden"
          >
            <div
              class="card-header text-white"
              style="
                background: linear-gradient(135deg, #28a745 0%, #20c997 100%);
                border: none;
              "
            >
              <div class="d-flex align-items-center">
                <i class="bi bi-trophy me-3" style="font-size: 2rem"></i>
                <div>
                  <h3 class="mb-1">面试结果</h3>
                  <p class="mb-0 opacity-75">恭喜您完成了AI面试</p>
                </div>
              </div>
            </div>
            <div class="card-body p-5">
              <div class="row mb-5">
                <div class="col-md-6">
                  <div class="d-flex align-items-center">
                    <div
                      class="bg-primary bg-opacity-10 rounded-circle p-3 me-3"
                    >
                      <i class="bi bi-briefcase text-primary"></i>
                    </div>
                    <div>
                      <h6 class="text-muted mb-1">应聘职位</h6>
                      <h5 class="mb-0">[[${interview.jobPosition}]]</h5>
                    </div>
                  </div>
                </div>
                <div class="col-md-6">
                  <div class="d-flex align-items-center">
                    <div class="bg-info bg-opacity-10 rounded-circle p-3 me-3">
                      <i class="bi bi-calendar-check text-info"></i>
                    </div>
                    <div>
                      <h6 class="text-muted mb-1">完成日期</h6>
                      <h5 class="mb-0">[[${interview.endTime}]]</h5>
                    </div>
                  </div>
                </div>
              </div>

              <div class="text-center mb-5">
                <div class="bg-light rounded-4 p-5">
                  <div class="display-1 fw-bold text-primary mb-2">
                    [[${#numbers.formatDecimal(interview.finalScore, 1, 'COMMA',
                    1, 'POINT')}]]
                  </div>
                  <div class="fs-4 text-muted mb-4">/ 10.0</div>
                  <div
                    class="progress mx-auto"
                    style="width: 60%; height: 20px; border-radius: 10px"
                  >
                    <div
                      class="progress-bar h-100"
                      role="progressbar"
                      th:style="'width: ' + ${interview.finalScore * 10} + '%;'"
                      th:classappend="${(interview.finalScore >= 7) ? 'bg-success' : ((interview.finalScore >= 4) ? 'bg-warning' : 'bg-danger')}"
                      aria-valuenow="${interview.finalScore}"
                      aria-valuemin="0"
                      aria-valuemax="10"
                      style="border-radius: 10px"
                    ></div>
                  </div>
                  <div class="mt-3">
                    <span
                      th:if="${interview.finalScore >= 7}"
                      class="badge bg-success fs-6 px-3 py-2"
                    >
                      <i class="bi bi-star-fill me-1"></i>优秀
                    </span>
                    <span
                      th:if="${interview.finalScore >= 4 && interview.finalScore < 7}"
                      class="badge bg-warning text-dark fs-6 px-3 py-2"
                    >
                      <i class="bi bi-star me-1"></i>良好
                    </span>
                    <span
                      th:if="${interview.finalScore < 4}"
                      class="badge bg-danger fs-6 px-3 py-2"
                    >
                      <i class="bi bi-exclamation-triangle me-1"></i>需改进
                    </span>
                  </div>
                </div>
              </div>

              <div class="mb-5">
                <h4 class="d-flex align-items-center mb-4">
                  <i class="bi bi-chat-square-text text-primary me-3"></i>
                  总体反馈
                </h4>
                <div
                  class="card border-0 shadow-sm"
                  style="border-radius: 15px"
                >
                  <div class="card-body p-4">
                    <p th:text="${interview.feedback}" class="mb-0 lh-lg"></p>
                  </div>
                </div>
              </div>

              <!-- 传统面试问题明细 -->
              <div th:if="${questions != null && !questions.isEmpty()}">
                <h4>问题明细</h4>
                <div th:each="question : ${questions}" class="card mb-3">
                  <div class="card-header">
                    <div
                      class="d-flex justify-content-between align-items-center"
                    >
                      <h5 class="mb-0">问题 [[${question.questionNumber}]]</h5>
                      <span
                        class="badge"
                        th:classappend="${(question.score >= 7) ? 'bg-success' : ((question.score >= 4) ? 'bg-warning' : 'bg-danger')}"
                      >
                        得分: [[${#numbers.formatDecimal(question.score, 1,
                        'COMMA', 1, 'POINT')}]]/10
                      </span>
                    </div>
                  </div>
                  <div class="card-body">
                    <p class="card-text">
                      <strong>问题:</strong> [[${question.question}]]
                    </p>
                    <p class="card-text">
                      <strong>你的回答:</strong> [[${question.userAnswer}]]
                    </p>
                    <p class="card-text">
                      <strong>反馈:</strong> [[${question.aiFeedback}]]
                    </p>
                  </div>
                </div>
              </div>

              <!-- 聊天式面试对话记录 -->
              <div
                th:if="${questions == null || questions.isEmpty()}"
                th:with="chatMessages=${interview.chatMessages}"
              >
                <h4>面试对话记录</h4>
                <div
                  th:if="${chatMessages != null && !chatMessages.isEmpty()}"
                  class="card"
                >
                  <div class="card-body">
                    <div th:each="msg : ${chatMessages}" class="mb-3">
                      <div
                        th:if="${msg.sender.name() == 'USER'}"
                        class="d-flex justify-content-end"
                      >
                        <div
                          class="bg-primary text-white p-3 rounded"
                          style="max-width: 70%"
                        >
                          <strong>您:</strong> [[${msg.content}]] <br /><small
                            class="text-light"
                            >[[${msg.timestamp}]]</small
                          >
                        </div>
                      </div>
                      <div
                        th:if="${msg.sender.name() == 'AI'}"
                        class="d-flex justify-content-start"
                      >
                        <div
                          class="bg-light p-3 rounded"
                          style="max-width: 70%"
                        >
                          <strong>AI面试官:</strong> [[${msg.content}]]
                          <br /><small class="text-muted"
                            >[[${msg.timestamp}]]</small
                          >
                        </div>
                      </div>
                    </div>
                  </div>
                </div>
                <div
                  th:if="${chatMessages == null || chatMessages.isEmpty()}"
                  class="alert alert-info"
                >
                  暂无对话记录
                </div>
              </div>

              <div class="text-center mt-5">
                <a
                  th:href="@{/interview}"
                  class="btn btn-primary btn-lg me-3"
                  style="
                    background: linear-gradient(
                      135deg,
                      #667eea 0%,
                      #764ba2 100%
                    );
                    border: none;
                    border-radius: 15px;
                  "
                >
                  <i class="bi bi-plus-circle me-2"></i>开始新面试
                </a>
                <a
                  th:href="@{/interviews}"
                  class="btn btn-outline-secondary btn-lg"
                  style="border-radius: 15px"
                >
                  <i class="bi bi-list-ul me-2"></i>查看所有面试
                </a>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>

    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/js/bootstrap.bundle.min.js"></script>
  </body>
</html>
